use std::net::TcpStream;
use std::net::SocketAddr;
use std::io::Result;

use std::io::Read;

pub struct TcpConnection{
    ///连接
    stream: TcpStream,

    ///远程ip
    ip: SocketAddr,

    ///协议类型：1表示http, 2表示web socket，其他值不支持
    protocol: u8,

    ///连接id
    id: u32
}

impl TcpConnection{
    pub fn new(id: u32, ip: SocketAddr, stream: TcpStream) -> TcpConnection{
        TcpConnection{
            stream,
            ip,
            protocol: 1u8,
            id
        }
    }

    pub fn read(&mut self, buffer: &mut [u8]) -> Result<usize>{
        self.stream.read(buffer)
    }
}